package com.ocm.burnningstar.View;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ocm.burnningstar.R;

/**
 * Created by ocm on 2018-01-31.
 */

public class TipView extends LinearLayout {
    View dip;
    TextView state;

    public TipView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.tip_item1, this, true);
        TypedArray tArray = context.obtainStyledAttributes(attrs,R.styleable.TipAttr);
        String stateAttr = tArray.getString(R.styleable.TipAttr[0]);
        dip = (View) findViewById(R.id.dip);
        state = (TextView) findViewById(R.id.state);
        setState(stateAttr);
        tArray.recycle();
    }

    public void setState(String val) {
        switch (val){
            case "1":
                dip.setBackgroundResource (R.drawable.dip4);
                state.setText("空闲状态");
                break;
            case "2":
                dip.setBackgroundResource (R.drawable.dip3);
                state.setText("热身燃脂");
                break;
            case "3":
                dip.setBackgroundResource (R.drawable.dip2);
                state.setText("充分燃脂");
                break;
            case "4":
                dip.setBackgroundResource (R.drawable.dip1);
                state.setText("极限状态");
                break;
            default:
                dip.setBackgroundResource (R.drawable.dip4);
                state.setText("空闲状态");
        }
    }
}
